/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ejb;

import entidades.Armazem;
import excecoes.EntidadeExistenteException;

import javax.ejb.EJBException;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author Joel
 */
@Stateless
public class ArmazemBean {

      @PersistenceContext
    private EntityManager em;   

    public void criarArmazem(int id) throws EntidadeExistenteException{
        try {
             
            Armazem armazem = em.find(Armazem.class, id);

            if(armazem != null){

                throw new EntidadeExistenteException();
            }

            em.persist(new Armazem(id));
       
        } catch (Exception e) {
            throw new EJBException(e.getMessage());
        }
    }   
    
}
